<?php

  /*

      TravianWAP
      Copyright (c) 2007-08 by Ananas - All rights reserved
      http://n00bz.biz/travianwap/
      Contact: uroskn@gmail.com

      --------------------------------------------------------------------------

      This program is free software: you can redistribute it and/or modify
      it under the terms of the GNU  General Public License as published by
      the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU  General Public License
      along with this program. If not, see http://www.gnu.org/licenses/.

  */

  global $text, $req;
  echo "<strong>Main building</strong><br/>\n";
  
  if (!empty($req["twaprem"]))
  {
    $request = array(
      "gid"    => $req["gid"],
      "a"      => $req["a"],
      "abriss" => $req["bid"],
      "ok"     => "demolish"
    );
    $info = http_post("http://{$_SESSION["serv"]}/build.php", $request);
  }
  
  if (!empty($info["body"])) $info = travian_return_main_building_info($info["body"], $req["id"], True);
  else $info = travian_return_main_building_info($text, $req["id"], True);
  
  if ($info["active_dem"])
  {
    echo "Demolish in progress ".
         print_link("main.php?mod=direct_call&amp;".htmlspecialchars($info["url"])."&amp;file=build&amp;return=details_build&amp;id={$req["id"]}".ps(), "[X]")."<br/>{$info["title"]}<br/>".pdate($info["remain"]).
         " - ".pdate($info["at"])."<br/><br/>";
  }
  else
  {
    $pfields = array(
      "mod"     => "details_build",
      "id"      => $req["id"],
      "gid"     => $info["gid"],
      "a"       => $info["a"],
      "bid"     => '$(bid)',
      "twaprem" => "twaprem"
    );
    print_form_top("main.php".ps('?'), $pfields, "get");
    echo "Building to demolish:<br/><select name=\"bid\">";
    for ($i = 0; $i <= 22; $i++) if ($info[$i]["ok"]) echo "<option value=\"{$info[$i]["id"]}\">{$info[$i]["name"]}</option>";
    echo '</select><br/>';
    print_form_bottom("Demolish");
  }

?>
